home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / Gooey1.3.1 / C++ Templates / mmMenu.c < prev    next >
Text File  |  1993-11-21  |  5KB  |  191 lines

  1. $$Message MM Menu, mm:mmMenu$Prototype.name$.cp
  2. $$File mm:mmMenu$Prototype.name$.cp
  3. /*  $CopyRight$ */
  4. /*  mmMenu$Prototype.name$                Handle menus
  5.  
  6.     File name:  mmMenu$Prototype.name$
  7.     Function:  This contains the routines to handle menus.
  8.     History: $Date$ Original by $Author$
  9.  
  10.    */
  11.  
  12. #include "mmCommon$Prototype.name$.h"    /* Common */
  13. #include "Common$Prototype.name$.h"        /* Common */
  14.  
  15.  
  16. /* ======================================================= */
  17. /* ======================================================= */
  18.  
  19. /* Routine: Init */
  20. /* Purpose: Load in the menu lists and initialize the menubar */
  21.  
  22. void CmmMenus::Init()                                /* Initialize the menu bar */
  23. {
  24.  
  25. ClearMenuBar();                                        /* Clear any old menu bars */
  26.  
  27. $$Loop Menus
  28. /* This menu is  $Menu.FullName$ */
  29. Menu_$Menu.name$ = GetMenu(Res_Menu_$Menu.name$);    /* Get the menu from the resource file */
  30. InsertMenu(Menu_$Menu.name$,0);                        /* Insert this menu into the menu bar */
  31. $$if Menu.Apple
  32. AddResMenu(Menu_$Menu.name$,'DRVR');                /* Add in DAs */
  33. $$endif
  34.  
  35. $$EndLoop Menus
  36. $$Loop HierMenus
  37. /* This menu is  $Menu.FullName$ */
  38. Menu_$Menu.name$ = GetMenu(Res_Menu_$Menu.name$);    /* Get the menu from the resource file */
  39. InsertMenu(Menu_$Menu.name$,-1);                    /* Insert this menu into the menu bar */
  40.  
  41. $$EndLoop HierMenus
  42.  
  43. this->AddExtraMenus();                                /* Add any extra menu lists */
  44.  
  45. DrawMenuBar();                                        /* Draw the menu bar */
  46. }
  47.  
  48. /* ======================================================= */
  49.  
  50. /* Routine: AddExtraMenus */
  51. /* Purpose: Add in more menus */
  52.  
  53. void CmmMenus::AddExtraMenus()
  54. {
  55. /* Expected to be overridden by the user code */
  56. }
  57.  
  58. /* ======================================================= */
  59.  
  60. /* Routine: EnableTheMenus */
  61. /* Purpose: Enable or disable menus before they are pulled down */
  62.  
  63. void CmmMenus::EnableTheMenus()
  64. {
  65. /* Expected to be overridden by the user code */
  66. }
  67.  
  68. /* ======================================================= */
  69.  
  70. $$Loop Menus
  71. /* Routine: DoMenu$Menu.name$ */
  72. /* Purpose: Handle all menu items in this list */
  73.  
  74. Boolean CmmMenus::DoMenu$Menu.name$(short theItem)
  75. {
  76. $$if Menu.Apple
  77. short        DNA;                                /* For opening DAs */
  78. Str255        DAName;                                /* For getting DA name */
  79. GrafPtr        SavePort;                            /* Save current port when opening DAs */
  80. $$endif
  81. $$if Menu.Edit
  82. Boolean        BoolHolder;                        /* For SystemEdit result */
  83. $$endif
  84. Boolean        HandledTheMenuItem;
  85.  
  86.  
  87. HandledTheMenuItem = true;
  88. $$if Menu.Edit
  89. BoolHolder = SystemEdit(theItem - 1);        /* Let the DA do the edit to itself */
  90.  
  91. if (!BoolHolder)                            /* If not a DA then we get it */
  92.     {
  93.  
  94. $$endif
  95. switch (theItem)                            /* Handle all commands in this menu list */
  96.     {
  97.     $$Loop MenuItems
  98.     case MItem_$MenuItem.name$:                /* For item $MenuItem.FullName$ */
  99.         $$Link    Menu
  100.         $$if Menu.Quit
  101.         doneFlag = true;                    /* Quit */
  102.         $$endif
  103.         break;
  104.     $$EndLoop MenuItems
  105.     default:                                /* allow other buttons, trap for debug */
  106.         $$if Menu.Apple
  107.         GetPort(&SavePort);                    /* Save the current port */
  108.         GetItem(Menu_$Menu.name$,theItem, DAName);    /* Get the name of the DA selected */
  109.         DNA = OpenDeskAcc(DAName);            /*Open the DA selected */
  110.         SetPort(SavePort);                    /* Restore to the saved port */
  111.         $$endif
  112.         HandledTheMenuItem = false;
  113.         break;                                /* end of otherwise */
  114.     }                                        /* end of switch */
  115. $$if Menu.Edit
  116.     }
  117. else
  118.     HandledTheMenuItem = false;
  119. $$endif
  120. return(HandledTheMenuItem);
  121. }
  122.  
  123. /* ======================================================= */
  124.  
  125. $$EndLoop Menus
  126. $$Loop HierMenus
  127. /* Routine: DoMenu$Menu.name$ */
  128. /* Purpose: Handle all menu items in this list */
  129.  
  130. Boolean CmmMenus::DoMenu$Menu.name$(short theItem)
  131. {
  132. Boolean        HandledTheMenuItem;
  133.  
  134.  
  135. HandledTheMenuItem = true;
  136. switch (theItem)                            /* Handle all commands in this menu list */
  137.     {
  138.     $$Loop MenuItems
  139.     case MItem_$MenuItem.name$:                /* For item $MenuItem.FullName$ */
  140.         $$Link    Menu
  141.         break;
  142.     $$EndLoop MenuItems
  143.     default:                                /* allow other buttons, trap for debug */
  144.         HandledTheMenuItem = false;
  145.         break;                                /* end of otherwise */
  146.     }                                        /* end of switch */
  147. return(HandledTheMenuItem);
  148. }
  149.  
  150. /* ======================================================= */
  151.  
  152. $$EndLoop HierMenus
  153. /* ======================================================= */
  154.  
  155. /* Routine: HandleMenuSelection */
  156. /* Purpose: Vector off to the appropiate menu list handler */
  157.  
  158. Boolean CmmMenus::HandleMenuSelection(short theMenu,short theItem)
  159. {
  160. Boolean        HandledTheMenu;
  161.  
  162.  
  163. HandledTheMenu = true;
  164. switch (theMenu)                                    /* Do selected menu list */
  165.     {
  166.     $$Loop Menus
  167.     case Res_Menu_$Menu.name$:
  168.         DoMenu$Menu.name$(theItem);                    /* Go handle this list, $Menu.FullName$ */
  169.         break;
  170.     $$EndLoop Menus
  171.     $$Loop HierMenus
  172.     case Res_Menu_$Menu.name$:
  173.         DoMenu$Menu.name$(theItem);                    /* Go handle this list, $Menu.FullName$ */
  174.         break;
  175.     $$EndLoop HierMenus
  176.  
  177.     default:                                        /* allow other buttons, trap for debug */
  178.         HandledTheMenu = false;
  179.         break;                                        /* end of otherwise */
  180.     }                                                /* end of switch */
  181.  
  182. HiliteMenu(0);                                        /* Turn menu selection off */
  183. return(HandledTheMenu);
  184. }
  185.  
  186. /* ======================================================= */
  187. /* ======================================================= */
  188. $$CloseFile
  189.  
  190.  
  191.